package cordova.plugin.zmq;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

/**
 * 接收消息广播
 *
 * @author mj
 *         created at 2016/6/14
 */
public class ZMQPluginBroadcastReceiver extends BroadcastReceiver {

    public static final String ACTION = "update.notification";  //通知消息标识
    public static final String RECEIVE = "receive.message";   //普通消息标识

    @Override
    public void onReceive(Context context, Intent intent) {
        // 获取广播内容
        try {
            if (intent.getAction().equals(RECEIVE)) {  //发送普通消息监听
                Log.i("NotificationReceiver", intent.getStringExtra("message") + "2222222222222");
                ZMQPlugin.receiveGeneralMsg(intent.getStringExtra("message"));
            } else {  //发送通知消息监听
                Intent launchIntent = context.getPackageManager().
                        getLaunchIntentForPackage(context.getPackageName());
                launchIntent.setFlags(
                        Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
                context.startActivity(launchIntent);
                Log.i("NotificationReceiver", intent.getStringExtra("msg") + "11111111111111111");
                ZMQPlugin.receiveNotificationMsg(intent.getStringExtra("msg"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
